package com.wlts.wzy.LMGoodsModule.controller;


import com.wlts.wzy.Base.BaseEntity;
import com.wlts.wzy.KSGoodsModule.entity.KsCategory;
import com.wlts.wzy.KSGoodsModule.service.IKsCategoryService;
import com.wlts.wzy.LMGoodsModule.entity.LmAddress;
import com.wlts.wzy.LMGoodsModule.service.ILmAddressService;
import com.wlts.wzy.Result.Result;
import com.wlts.wzy.api.request.ks.KsCategoryPageRequest;
import com.wlts.wzy.api.request.lm.GetLmAddressPageRequest;
import com.wlts.wzy.expand.MyLambdaQueryWrapper;
import com.wlts.wzy.expand.MyPage;
import com.wlts.wzy.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 区域表 前端控制器
 * </p>
 *
 * @author zhiyong
 * @since 2021-01-30
 */
@Api(tags = "lm地址库")
@RestController
@RequestMapping("/LMGoodsModule/lm-address")
public class LmAddressController {

    @Autowired
    private ILmAddressService lmAddressService;

    @ApiModelProperty("分页获得LM地址库")
    @RequestMapping(value = "getLmAddressPage", method = RequestMethod.POST)
    public Result<MyPage<LmAddress>> getLmAddressPage(@RequestBody GetLmAddressPageRequest request) {

        //System.out.println(request.toString());

        MyLambdaQueryWrapper<LmAddress> queryWrapper = new MyLambdaQueryWrapper<>();

        queryWrapper.eq(BaseEntity::getDelFlag, "0");

        queryWrapper.eq(LmAddress::getParentId,request.getParentId());

        if(StringUtils.isNotEmpty(request.getDivisionName())){
            queryWrapper.like(LmAddress::getDivisionName,request.getDivisionName());
        }


        MyPage<LmAddress> page = lmAddressService.page(queryWrapper, request.getCurrentPage(), request.getPageSize(), true);

        return Result.buildResult(page);
    }


}
